<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑项目花名册</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">



        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="enginid">
                            <input type="text" id="enginid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目属性</label>
                        <div class="layui-input-block">
                            <input type="text" id="business_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">关联劳务合同</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="caiid" class="layui-input caiid" onclick="choose_contract_cai()">
                            <div class="choose_div" id="caiid" key="1"></div>
                            <span class="choose_one" onclick="choose_contract_cai()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">劳务合同编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="cainumber" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">班组名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="gonger" id="gonger" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">班组负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gonguser" id="gonguser" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>




        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>成员信息</span></div>
                        <div>
                            <button type="button" onclick="ctrlv_data_open()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">粘贴新增</button>
                            <button type="button" onclick="import_list()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">Excel导入</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>工种/岗位</th>
                            <th><text>*</text>姓名</th>
                            <th>手机号</th>
                            <th><text>*</text>性别</th>
                            <th>年龄</th>
                            <th>身份证号</th>
                            <th>家庭地址</th>
                            <th>班组名称</th>
                            <th>进场日期</th>
                            <th>退场日期</th>
                            <th>健康状况</th>
                            <th>身份证</th>
                            <th>合同情况</th>
                            <th>上岗证书</th>
                            <th>退场确认书</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;


    function choose_contract_cai(){
        var enginid = $("#enginid").val();
        openPage('../public/choose_contract_cai.php?dom=caiid&enginid='+enginid+'&page=labour_hua&caihetype=3','80%','80%')
    }

    function import_list() {
        openPage('../public/import.php?reveal=labour_hua@importdata', '770px', '490px');
    }



    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_labour_hua_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                var engininfo = res.data.engininfo;
                var caiidinfo = res.data.caiidinfo;

                $("#enginid").val(engininfo.id);
                $("#enginid_name").val(engininfo.name);
                $("#business_name").val(engininfo.business_name);
                $("#gonger").val(data.gonger);
                $("#gonguser").val(data.gonguser);
                $("#explain").val(data.explain);


                if(caiidinfo){
                    set_choose_btn('caiid',caiidinfo.id,caiidinfo.name);
                    $("#cainumber").val(caiidinfo.number);
                }

                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td><input type="text" class="layui-input place"></td>';
                listAddStr += '<td><input type="text" class="layui-input name"></td>';
                listAddStr += '<td><input type="text" class="layui-input tel"></td>';
                listAddStr += '<td><input type="text" class="layui-input sex"></td>';
                listAddStr += '<td><input type="text" class="layui-input age"></td>';
                listAddStr += '<td><input type="text" class="layui-input idcard"></td>';
                listAddStr += '<td><input type="text" class="layui-input addr"></td>';
                listAddStr += '<td><input type="text" class="layui-input banname"></td>';
                listAddStr += '<td><input type="text" class="layui-input jindt bdate_ymd" readonly></td>';
                listAddStr += '<td><input type="text" class="layui-input tuidt bdate_ymd" readonly></td>';
                listAddStr += '<td><input type="text" class="layui-input jian"></td>';
                listAddStr += '<td>'+public_show_file_deta('list_list', [], 1, 1)+'</td>';
                listAddStr += '<td>'+public_show_file_deta('list_list', [], 1, 2)+'</td>';
                listAddStr += '<td>'+public_show_file_deta('list_list', [], 1, 3)+'</td>';
                listAddStr += '<td>'+public_show_file_deta('list_list', [], 1, 4)+'</td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1);

                var list = res.data.list;
                if(list.length > 0){
                    var str = '';
                    for (var key in list){
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td><input type="text" class="layui-input place" value="'+list[key].place+'"></td>';
                        str += '<td><input type="text" class="layui-input name" value="'+list[key].name+'"></td>';
                        str += '<td><input type="text" class="layui-input tel" value="'+list[key].tel+'"></td>';
                        str += '<td><input type="text" class="layui-input sex" value="'+list[key].sex+'"></td>';
                        str += '<td><input type="text" class="layui-input age" value="'+list[key].age+'"></td>';
                        str += '<td><input type="text" class="layui-input idcard" value="'+list[key].idcard+'"></td>';
                        str += '<td><input type="text" class="layui-input addr" value="'+list[key].addr+'"></td>';
                        str += '<td><input type="text" class="layui-input banname" value="'+list[key].banname+'"></td>';
                        str += '<td><input type="text" class="layui-input jindt bdate_ymd" value="'+list[key].jindt+'" readonly></td>';
                        str += '<td><input type="text" class="layui-input tuidt bdate_ymd" value="'+list[key].tuidt+'" readonly></td>';
                        str += '<td><input type="text" class="layui-input jian" value="'+list[key].jian+'"></td>';
                        str += '<td>'+public_show_file_deta('list_list', list[key].file_shen_arr, 1, 1)+'</td>';
                        str += '<td>'+public_show_file_deta('list_list', list[key].file_he_arr, 1, 2)+'</td>';
                        str += '<td>'+public_show_file_deta('list_list', list[key].file_gang_arr, 1, 3)+'</td>';
                        str += '<td>'+public_show_file_deta('list_list', list[key].file_book_arr, 1, 4)+'</td>';
                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                    }
                    $("#list_list").html(str);
                }

                public_upload_file_load('upload_files', res.data.files)
                render_from();
                initParseMoney();
            }
        });



        form.on('submit(add)', function(data){
            data.field.caiid = get_choose_val('caiid');
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}





            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var place = $(this).find('.place').val();
                    var name = $(this).find('.name').val();
                    var tel = $(this).find('.tel').val();
                    var sex = $(this).find('.sex').val();
                    var age = $(this).find('.age').val();
                    var idcard = $(this).find('.idcard').val();
                    var addr = $(this).find('.addr').val();
                    var banname = $(this).find('.banname').val();
                    var jindt = $(this).find('.jindt').val();
                    var tuidt = $(this).find('.tuidt').val();
                    var jian = $(this).find('.jian').val();
                    var file_shen = public_deta_file_value(this, 1);
                    var file_he = public_deta_file_value(this, 2);
                    var file_gang = public_deta_file_value(this, 3);
                    var file_book = public_deta_file_value(this, 4);
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!name){
                        throw new Error('第'+index+'行，请输入姓名');
                    }
                    if(!sex){
                        throw new Error('第'+index+'行，请输入性别');
                    }

                    list.push({
                        place:place,
                        name:name,
                        tel:tel,
                        sex:sex,
                        age:age,
                        idcard:idcard,
                        addr:addr,
                        banname:banname,
                        jindt:jindt,
                        tuidt:tuidt,
                        jian:jian,
                        file_shen:file_shen,
                        file_he:file_he,
                        file_gang:file_gang,
                        file_book:file_book,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;

            data.field.id = param_id;
            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_labour_hua_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });



    });


    var ctrlv_field_name = [
        {field: 'place', name:'工种/岗位'},
        {field: 'name', name:'姓名'},
        {field: 'tel', name:'手机号'},
        {field: 'sex', name:'性别'},
        {field: 'age', name:'年龄'},
        {field: 'idcard', name:'身份证号'},
        {field: 'addr', name:'家庭地址'},
        {field: 'banname', name:'班组名称'},
        {field: 'jindt', name:'进场日期',type:'date'},
        {field: 'tuidt', name:'退场日期',type:'date'},
        {field: 'jian', name:'健康状况'},
        {field: 'explain', name:'备注'},
    ];
    function ctrlv_data_show(list) {
        if(list.length > 0){
            var nums = $("#list_list tr").length;
            for (var key in list){
                var str = '';
                nums++;
                str += '<tr>';
                str += '<td style="width: 45px">'+nums+'</td>';
                str += '<td><input type="text" class="layui-input place" value="'+list[key].place+'"></td>';
                str += '<td><input type="text" class="layui-input name" value="'+list[key].name+'"></td>';
                str += '<td><input type="text" class="layui-input tel" value="'+list[key].tel+'"></td>';
                str += '<td><input type="text" class="layui-input sex" value="'+list[key].sex+'"></td>';
                str += '<td><input type="text" class="layui-input age" value="'+list[key].age+'"></td>';
                str += '<td><input type="text" class="layui-input idcard" value="'+list[key].idcard+'"></td>';
                str += '<td><input type="text" class="layui-input addr" value="'+list[key].addr+'"></td>';
                str += '<td><input type="text" class="layui-input banname" value="'+list[key].banname+'"></td>';
                str += '<td><input type="text" class="layui-input jindt bdate_ymd" value="'+list[key].jindt+'" readonly></td>';
                str += '<td><input type="text" class="layui-input tuidt bdate_ymd" value="'+list[key].tuidt+'" readonly></td>';
                str += '<td><input type="text" class="layui-input jian" value="'+list[key].jian+'"></td>';
                str += '<td>'+public_show_file_deta('list_list', [], 1, 1)+'</td>';
                str += '<td>'+public_show_file_deta('list_list', [], 1, 2)+'</td>';
                str += '<td>'+public_show_file_deta('list_list', [], 1, 3)+'</td>';
                str += '<td>'+public_show_file_deta('list_list', [], 1, 4)+'</td>';
                str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                str += '</tr>';
                $("#list_list").append(str);
            }
        }
        render_date();
        render_from();
    }
</script>
</body>
</html>
